<template>
  <el-card shadow="never" class="mb20">
    <div class="table-page-search-wrapper">
      <el-form :model="form" ref="form" :inline="true" label-width="80px">
        <el-row :gutter="16">
          <el-col :span="6">
            <el-form-item>
              <el-date-picker
                style="width: 100%"
                v-model="date"
                type="daterange"
                range-separator="-"
                value-format="yyyy-MM-dd"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
              ></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item>
              <el-checkbox v-model="form.dateState">账期</el-checkbox>
              <el-checkbox class="mr20" v-model="form.deptState">科室名称</el-checkbox>
              <el-checkbox class="mr20" v-model="form.docNameState">开单医生</el-checkbox>
            </el-form-item>
          </el-col>
          <el-col :span="3" v-show="form.deptState">
            <el-form-item prop="deptName">
              <el-input v-model="form.deptName" placeholder="科室名称" />
            </el-form-item>
          </el-col>
          <el-col :span="3" v-show="form.docNameState">
            <el-form-item prop="docName">
              <el-input v-model="form.docName" placeholder="医生名称" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item>
              <el-tooltip class="item" effect="dark" content="查询" placement="top">
                <el-button icon="el-icon-search" type="primary" @click="handleSearch" />
              </el-tooltip>
              <el-tooltip class="item" effect="dark" content="重置" placement="top">
                <el-button icon="el-icon-refresh-right" @click="handleReset" />
              </el-tooltip>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
  </el-card>
</template>

<script>
import { boolTransNum, getPreMonth } from '@/utils/util'
export default {
  data() {
    return {
      date: null,
      form: {
        dateState: false,
        deptState: true,
        docNameState: false,
        pageNo: 1
      }
    }
  },
  computed: {
    timeDefault() {
      var date = new Date()
      const nowDay = this.formatTime(date, 'day')
      const preDay = getPreMonth(nowDay)
      console.log('time', nowDay, preDay)
      return [preDay, nowDay]
    }
  },
  mounted() {
    this.date = this.timeDefault
    this.handleSearch()
  },
  methods: {
    handleSearch() {
      if (this.date) {
        this.$set(this.form, 'startTime', this.date[0])
        this.$set(this.form, 'endTime', this.date[1])
      } else {
        this.$set(this.form, 'startTime', null)
        this.$set(this.form, 'endTime', null)
      }
      const form = boolTransNum(this.form)

      console.log('form', form)
      this.$emit('search', form)
    },
    handleReset() {
      this.$refs.form.resetFields()
      this.handleSearch()
    }
  }
}
</script>
